package com.frxuexi.mdm2206.demo

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage

@Preview
@Composable
fun Demo04() {
    val pagerState = rememberPagerState {
        5
    }
    val list = listOf<String>(
        "https://img1.baidu.com/it/u=4214113141,2036563917&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1731603600&t=4d6f50de01a6b2ba0cfad5e77060c1eb",
        "https://img0.baidu.com/it/u=540669065,2162680038&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1731603600&t=4013e7a15c201577f9177620c1454c18",
        "https://img2.baidu.com/it/u=553712968,3437602612&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1731603600&t=d4823f806f29c31469dcdad22dcc1388",
        "https://img0.baidu.com/it/u=3267261432,3027407616&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1731603600&t=04425b33e7b9fd6751b7725511c82679",
        "https://img0.baidu.com/it/u=788800651,2030194952&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1731603600&t=cbc956b2d424da99361ac542b3055d1c"
    )

    /*轮播图*/
    Column {
        HorizontalPager(state = pagerState, verticalAlignment = Alignment.Top, modifier = Modifier
            .fillMaxWidth()
            .height(200.dp)) {
            AsyncImage(model = list.get(it), contentDescription = "",
                modifier = Modifier
                    .fillMaxWidth()
                    .height(200.dp), contentScale = ContentScale.Crop)
        }
        Row(Modifier.fillMaxWidth().offset(y=-30.dp), horizontalArrangement = Arrangement.Center) {
            repeat(pagerState.pageCount){
                var color=if(pagerState.currentPage==it) Color.DarkGray else Color.LightGray
                Box(modifier = Modifier
                    .size(20.dp)
                    .padding(5.dp)
                    .background(color, CircleShape))
            }
        }
    }

    /*引导页*/
    /*Box(contentAlignment= Alignment.BottomCenter) {
        HorizontalPager(state = pagerState, verticalAlignment = Alignment.Top, modifier = Modifier
            .fillMaxWidth()
            .fillMaxHeight()) {
            AsyncImage(model = list.get(it), contentDescription = "",
                modifier = Modifier
                    .fillMaxWidth()
                    .fillMaxHeight(), contentScale = ContentScale.Crop)
        }
        Row(Modifier.fillMaxWidth().offset(y=-20.dp), horizontalArrangement = Arrangement.Center) {
            repeat(pagerState.pageCount){
                var color=if(pagerState.currentPage==it) Color.DarkGray else Color.LightGray
                Box(modifier = Modifier
                    .size(20.dp)
                    .padding(5.dp)
                    .background(color, CircleShape))
            }
        }
    }*/


}